package com.example.jay10_8;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link WeixinFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class WeixinFragment extends Fragment {

    private List<String> mList;

    private View view;

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public WeixinFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment BlankFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static WeixinFragment newInstance(String param1, String param2) {
        WeixinFragment fragment = new WeixinFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }
    private void InitRecyclerView(){
        RecyclerView mRecyclerView = view.findViewById(R.id.tab01_1);

        HomeAdapter mHomeAdapter = new HomeAdapter(getActivity(), mList);
        mRecyclerView.setAdapter(mHomeAdapter);
        // 设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL,false);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        // 设置 item 增加和删除时的动画
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());

//        mHomeAdapter.setOnItemClickListener(new HomeAdapter.OnItemClickListener(){
//            @Override
//            public void OnItemClick(View view, List<String> mList) {
//                //此处进行监听事件的业务处理
//                Toast.makeText(getActivity(),"我是item",Toast.LENGTH_SHORT).show();
//            }
//
//        });

    }

    private List<String> getList() {
        List<String> list = new ArrayList<>();
        List<String> list1 = new ArrayList<>();
        list.add("吉安娜");
        list.add("陈康王");
        list.add("麦格尼");
        list.add("卡德加");
        list.add("安度因");
        list.add("ddg");
        list.add("陈凯歌");
        list.add("玛法里奥");
        list.add("乌瑟尔");
        list.add("吉安娜");
        list.add("陈康王");
        list.add("麦格尼");
        list.add("卡德加");
        list.add("安度因");
        list.add("ddg");
        list.add("陈凯歌");
        list.add("玛法里奥");
        list.add("乌瑟尔");
        list.add("吉安娜");
        list.add("陈康王");
        list.add("麦格尼");
        list.add("卡德加");
        list.add("安度因");
        list.add("ddg");
        list.add("陈凯歌");
        list.add("玛法里奥");
        list.add("乌瑟尔");
        list.add("吉安娜");
        list.add("陈康王");
        list.add("麦格尼");
        list.add("卡德加");
        list.add("安度因");
        list.add("ddg");
        list.add("陈凯歌");
        list.add("玛法里奥");
        list.add("乌瑟尔");

        for (int i =0;i<list.size();i++){
            list1.add((i+1)+":"+list.get(i));
        }

        return list1;

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mList = getList();
        view = inflater.inflate(R.layout.tab01, container, false);
        //对recycleview进行配置
        InitRecyclerView();



        return view;
    }
}